package com.hp.attendance.serlvet.department;

import com.hp.attendance.entity.Department;
import com.hp.attendance.service.DepartmentService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;




@WebServlet("/updateDepartment")
public class DepartmentUpdateServlet extends HttpServlet {
    private DepartmentService departmentService = new DepartmentService();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //修改
        try {
            String name = req.getParameter("name");
            String telephone = req.getParameter("telephone");
            String address = req.getParameter("address");
            String notes = req.getParameter("notes");
            String id = req.getParameter("id");
            String department_number = req.getParameter("department_number");
            Department department = new Department(Integer.parseInt(id),Integer.parseInt(department_number), name, null, telephone, address, notes);
            departmentService.updateDepartment(department);


            //跳转到list列表
            req.getRequestDispatcher("/DepartmentPageServlet").forward(req,resp);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
